home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/wingfx.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* wingfx.h: header for wingfx.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define wingfx.h 1
-
- #include "all.h"
- #include "newext.h"
-
- static Pixwin *pw;
- static int width, height;
- static float h_scalex, h_scaley, h_basex, h_basey;
- static float w_scalex, w_scaley, w_basex, w_basey;
- static float i_scalex, i_scaley, i_basex, i_basey;
- static Raster last;
- static Clipper c2d;
-
- static int clipt ();
-
- /* EOF */
- /* cat > src+obj/wingfx/clip2d.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* clip2d: clip 2-D */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- clip2d (fx, fy, tx, ty, clp)
- int *fx, *fy, *tx, *ty;
- Clipper *clp;
- {
- float t0, t1;
- float deltax, deltay;
- float lx0, ly0;
- float lx1, ly1;
- int isok = FALSE;
-
- lx0 = (float) *fx;
- ly0 = (float) *fy;
- lx1 = (float) *tx;
- ly1 = (float) *ty;
-
- t0 = 0.0;
- t1 = 1.0;
- deltax = lx1 - lx0;
- if (clipt (-deltax, lx0 - (clp->clip_xmin), &t0, &t1) &&
- clipt (deltax, (clp->clip_xmax) - lx0, &t0, &t1))
- {
-
- deltay = ly1 - ly0;
-
- if (clipt (-deltay, ly0 - (clp->clip_ymin), &t0, &t1) &&
- clipt (deltay, (clp->clip_ymax) - ly0, &t0, &t1))
- {
-
- isok = TRUE;
-
- if (t1 < 1.0)
- {
- lx1 = lx0 + t1 * deltax;
- ly1 = ly0 + t1 * deltay;
- }
-
- if (t0 > 0.0)
- {
- lx0 = lx0 + t0 * deltax;
- ly0 = ly0 + t0 * deltay;
- }
- }
- }
-
- *fx = ROUND (lx0);
- *fy = ROUND (ly0);
- *tx = ROUND (lx1);
- *ty = ROUND (ly1);
- return (isok);
- }
- /* EOF */
- /* cat > src+obj/wingfx/clipt.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* clipt: (static) Line clipping algorithms as taken */
- /* from ACM TOG Vol 3 No 1. The bounding area */
- /* for the X-Y plane is defined by the points */
- /* (clip_xmin, clip_ymin) and */
- /* (clip_xmax, clip_ymax). For the 3-D case, the */
- /* hither plane corresponds to clip_zmin and */
- /* the yon plan corresponds to clip_zmax */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- static int
- clipt (p, q, t0, t1)
- float p, q;
- float *t0, *t1;
- {
- float r;
-
- if (p < 0.0)
- {
- r = q / p;
- if (r > *t1)
- return (FALSE);
- else if (r > *t0)
- *t0 = r;
- }
- else if (p > 0.0)
- {
- r = q / p;
- if (r < *t0)
- return (FALSE);
- else if (r < *t1)
- *t1 = r;
- }
- else if (q < 0.0)
- return (FALSE);
-
- return (TRUE);
- }
- /* EOF */
- /* cat > src+obj/wingfx/gfx_init.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* gfx_init: gfx initialization */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- void
- gfx_init ()
- {
- pw = (Pixwin *) canvas_pixwin (pcanvas);
- width = (int) window_get (pcanvas, WIN_WIDTH);
- height = (int) window_get (pcanvas, WIN_HEIGHT);
-
- c2d.clip_xmin = 0;
- c2d.clip_xmax = width;
- c2d.clip_ymin = 0;
- c2d.clip_ymax = height;
- }
- /* EOF */
- /* cat > src+obj/wingfx/gfx_line.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* gfx_line: gfx line */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- void
- gfx_line (fx, fy, tx, ty, flag)
- float fx, fy, tx, ty;
- int flag;
- {
- gfx_move (fx, fy);
- gfx_vector (tx, ty, flag);
- }
- /* EOF */
- /* cat > src+obj/wingfx/gfx_move.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* gfx_move: gfx move */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- void
- gfx_move (tx, ty)
- float tx, ty;
- {
- tx = h_scalex * tx + h_basex;
- last.x = ROUND (tx);
- ty = h_scaley * ty + h_basey;
- last.y = ROUND (ty);
- }
- /* EOF */
- /* cat > src+obj/wingfx/gfx_vector.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* gfx_vector: gfx vector */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- void
- gfx_vector (tx, ty, flag)
- float tx, ty;
- int flag;
- {
- Raster sf, lf;
-
- sf = last;
- gfx_move (tx, ty);
- lf = last;
-
- if (flag)
- draw_hline (sf.x, sf.y, lf.x, lf.y);
- else
- plot_line (sf.x, sf.y, lf.x, lf.y);
- }
- /* EOF */
- /* cat > src+obj/wingfx/hid_scale.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* hid_scale: scaling */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- void
- hid_scale (minx, maxx, miny, maxy)
- float minx, maxx, miny, maxy; /* box boundaries */
- {
- /* Mapped to a 2-D space with PRECISION pixels horizontally. */
- h_scalex = (float) PRECISION / (maxx - minx);
- h_scaley = h_scalex;
- h_basex = -(h_scalex * minx);
- h_basey = -(h_scaley * miny);
- }
- /* EOF */
- /* cat > src+obj/wingfx/plot_line.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* plot_line: plot line */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- void
- plot_line (x1, y1, x2, y2)
- int x1, y1, x2, y2;
- {
- Point f, t;
- float xf, yf, xt, yt;
-
- if (graph_mode == PLOT_3D)
- {
- f.x = (float) x1 - h_basex;
- f.y = (float) y1 - h_basey;
- t.x = (float) x2 - h_basex;
- t.y = (float) y2 - h_basey;
- zform (&f);
- zform (&t);
- f.x += h_basex;
- f.y += h_basey;
- t.x += h_basex;
- t.y += h_basey;
- }
- else
- {
- f.x = x1;
- f.y = y1;
- t.x = x2;
- t.y = y2;
- }
-
- xf = i_scalex * f.x + i_basex;
- yf = i_scaley * f.y + i_basey;
- xt = i_scalex * t.x + i_basex;
- yt = i_scaley * t.y + i_basey;
-
- f.x = w_scalex * f.x + w_basex;
- f.y = w_scaley * f.y + w_basey;
- t.x = w_scalex * t.x + w_basex;
- t.y = w_scaley * t.y + w_basey;
-
- x1 = ROUND (f.x);
- y1 = ROUND (f.y);
- x2 = ROUND (t.x);
- y2 = ROUND (t.y);
-
- if (x1 >= width || x1 <= 0 ||
- y1 >= height || y1 <= 0 ||
- x2 >= width || x2 <= 0 ||
- y2 >= height || y2 <= 0)
- {
-
- if (!clip2d (&x1, &y1, &x2, &y2, &c2d))
- return;
- }
-
- if (x1 == x2 && y1 == y2)
- return;
- pw_vector (pw, x1, y1, x2, y2, PIX_SRC, 255);
- lw_line (xf, yf, xt, yt);
- }
- /* EOF */
- /* cat > src+obj/wingfx/win_scale.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* win_scale: window scaling */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "wingfx.h" */
-
- void
- win_scale (minx, maxx, miny, maxy)
- float minx, maxx, miny, maxy; /* box boundaries */
- {
- /* Mapped to the real window 2-D space. */
- minx = h_scalex * minx + h_basex;
- maxx = h_scalex * maxx + h_basex;
- miny = h_scaley * miny + h_basey;
- maxy = h_scaley * maxy + h_basey;
-
- w_scalex = (float) width / (maxx - minx);
- w_scaley = (float) height / (maxy - miny);
-
- if (w_scalex < w_scaley)
- {
- w_scaley = w_scalex;
- w_basex = -w_scalex * minx;
- w_basey = -w_scaley * miny + (height - w_scaley * (maxy - miny)) * 0.5;
- }
- else
- {
- w_scalex = w_scaley;
- w_basey = -w_scaley * miny;
- w_basex = -w_scalex * minx + (width - w_scalex * (maxx - minx)) * 0.5;
- }
-
- i_scalex = (LW_WIDTH * 0.8) / (maxx - minx);
- i_scaley = (LW_HEIGHT * 0.8) / (maxy - miny);
-
- if (i_scalex < i_scaley)
- {
- i_scaley = i_scalex;
- i_basex = 0.1 * LW_WIDTH - i_scalex * minx;
- i_basey = 0.1 * LW_HEIGHT - i_scaley * miny
- + (0.8 * LW_HEIGHT - i_scaley * (maxy - miny)) * 0.5;
- }
- else
- {
- i_scalex = i_scaley;
- i_basey = 0.1 * LW_HEIGHT - i_scaley * miny;
- i_basex = 0.1 * LW_WIDTH - i_scalex * minx
- + (0.8 * LW_WIDTH - i_scalex * (maxx - minx)) * 0.5;
- }
- }
- /* EOF */
-